﻿<UserControl x:Class="Passwords.Views.SynView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:models="clr-namespace:Passwords.Models"
             xmlns:vm="clr-namespace:Passwords.ViewModels"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d"  d:DesignWidth="591" >
    <UserControl.Template>
        <ControlTemplate>
            <ControlTemplate.Resources>
                <ExponentialEase x:Key="ease" EasingMode="EaseOut" Exponent="5"/>
                <BackEase x:Key="bounce" EasingMode="EaseOut"  Amplitude="0.5"/>
            </ControlTemplate.Resources>
            <Grid x:Name="grid" Grid.Row="1" Background="{DynamicResource AppAccentBrush}" TextBlock.Foreground="White" Visibility="Collapsed" >
                <StackPanel x:Name="syncLoginPanel" Orientation="Horizontal"  Margin="5" HorizontalAlignment="Center" Visibility="Collapsed" >
                    <StackPanel.InputBindings>
                        <KeyBinding Key="Enter" Command="{x:Static vm:Commands.SyncLoginCommand}" CommandParameter="{Binding ElementName= passwordBox}"/>
                        <KeyBinding Key="Esc" Command="{x:Static vm:Commands.SyncLoginCommand}" />
                    </StackPanel.InputBindings>
                    <TextBlock Text="{Binding rs.EnterPhonePasswordToSync, Source={StaticResource locale}}" VerticalAlignment="Center" Margin="4"/>
                    <PasswordBox x:Name="passwordBox" MinWidth="120" Margin="4"/>
                    <Button Content="{Binding rs.SyncLoginBtn, Source={StaticResource locale}}" Margin="4" MinWidth="80" Command="{x:Static vm:Commands.SyncLoginCommand}" CommandParameter="{Binding ElementName= passwordBox}"/>
                    <Button Content="{Binding rs.SyncCancelBtn, Source={StaticResource locale}}" Margin="4" MinWidth="80" Command="{x:Static vm:Commands.SyncLoginCommand}"/>
                </StackPanel>
                <StackPanel x:Name="wrongPasswordPanel" Orientation="Horizontal" VerticalAlignment="Top" Margin="5" HorizontalAlignment="Center" Visibility="Collapsed" >
                    <StackPanel.InputBindings>
                        <KeyBinding Key="Esc" Command="{x:Static vm:Commands.ShowLoginCommand}"/>
                    </StackPanel.InputBindings>
                    <TextBlock Text="{Binding rs.LoginPasswordDidNotMatch, Source={StaticResource locale}}" Margin="4" VerticalAlignment="Center"/>
                    <Button Content="{Binding rs.Ok, Source={StaticResource locale}}" MinWidth="80" Margin="4" Command="{x:Static vm:Commands.ClearSyncPasswordErrorCommand}"/>
                </StackPanel>
                <StackPanel x:Name="progressPanel" HorizontalAlignment="Center" Orientation="Horizontal" Margin="5" VerticalAlignment="Top" Visibility="Collapsed" >
                    <TextBlock Text="{Binding Data.SyncContext.SyncText}" VerticalAlignment="Center" Margin="4"/>
                </StackPanel>
                <Grid.RenderTransform>
                    <TranslateTransform x:Name="translate"/>
                </Grid.RenderTransform>
            </Grid>
            <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding Data.SyncDisplayMode}" Value="{x:Static models:SyncDisplayMode.Login}">
                    <Setter Property="Visibility" Value="Visible" TargetName="grid"/>
                    <Setter Property="Visibility" Value="Visible" TargetName="syncLoginPanel"/>
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="translate" Storyboard.TargetProperty="Y"  From="80" To="0" 
                                                 EasingFunction="{StaticResource ease}" Duration="0:0:0.35"/>
                                <DoubleAnimation Storyboard.TargetName="grid" Storyboard.TargetProperty="Opacity"  From="0" To="1" 
                                                 EasingFunction="{StaticResource ease}" Duration="0:0:0.2"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
                <DataTrigger Binding="{Binding Data.SyncDisplayMode}" Value="{x:Static models:SyncDisplayMode.WrongPassword}">
                    <Setter Property="Visibility" Value="Visible" TargetName="grid"/>
                    <Setter Property="Visibility" Value="Visible" TargetName="wrongPasswordPanel"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Data.SyncDisplayMode}" Value="{x:Static models:SyncDisplayMode.Synchronize}">
                    <Setter Property="Visibility" Value="Visible" TargetName="grid"/>
                    <Setter Property="Visibility" Value="Visible" TargetName="progressPanel"/>
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="translate" Storyboard.TargetProperty="Y"  From="80" To="0" 
                                                 EasingFunction="{StaticResource ease}" Duration="0:0:0.35"/>
                                <DoubleAnimation Storyboard.TargetName="grid" Storyboard.TargetProperty="Opacity"  From="0" To="1" 
                                                 EasingFunction="{StaticResource ease}" Duration="0:0:0.2"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </UserControl.Template>

</UserControl>
